package com.liu.kafka.config.partition;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @author
 * @Date 2021/1/13 11:33
 * @Motto Keep thinking, keep coding!
 * Kafka的producer自定义分区器
 */
public class CustomPartitioner implements Partitioner {
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
//        Integer nums = cluster.partitionCountForTopic(topic);
//        return key.hashCode() % nums;
        return 1;
    }
    @Override
    public void close() {
    }
    @Override
    public void configure(Map<String, ?> configs) {
    }
}
